package com.lsc;



import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.lsc.blog.pojo.User;
import com.lsc.blog.mapper.UserMapper;
import com.lsc.blog.service.impl.UserServiceImpl;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;


/**
 * @program: mybatis_plus
 * @description: 测试
 * @author: 上河图
 * @create: 2020-10-06 13:06
 */
@SpringBootTest
public class test {

    //需要在主程序中添加，不然就会扫描不到这个接口，就会报没有找到对应的bean
    /*
    * @ComponentScan  扫描Mapper下的所有接口
      @ComponentScan("com.lsc.blog.mapper")
    * */
    @Autowired
    public UserMapper userMapper;

    @Test
    public void testSelect() {
        
//      页面分页 起始页0 最大容量2
        Page<User> page = new Page<>(0, 2);
       /* QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.gt("age", 20);
*/
        userMapper.selectPage(page, null);

//        获取分页好的值
        List<User> userList = page.getRecords();
        for (Object record : userList) {
            System.out.println(record);
        }
//        获取总页面
        System.out.println(page.getTotal());
    }

    @Autowired
    private UserServiceImpl userService;

    @Test
    public void testGetId(){

        User user = userService.getId(3);
        System.out.println(user);
    }
}
